---
layout: single
elementName: input
---

<section id="input" class="element">
  <header class="element-header">
    <nav class="element-links">
        <span>
          Type: <strong>inline</strong>
        </span>
      <span>
        Self-closing:
        <strong>
            Yes
        </strong>
      </span>
      <a class="element-links-direct" href="{{site.url}}/element/input/" data-element-name="input" data-tooltip="Single page for this element">Permalink</a>
      <a class="element-share" data-tooltip="Share on Twitter or Facebook" data-element-name="input">Share</a>
      <a target="_blank" href="https://developer.mozilla.org/en/docs/Web/HTML/Element/input" data-tooltip="See on Mozilla Developer Network" rel="external">MDN</a>
    </nav>
    <h2 class="element-name">
      <a href="#input">
        <span>#</span>
        input
      </a>
    </h2>
    <div class="element-description">
      <p>Defines an <strong>interactive control</strong> within a web form.</p>

    </div>
  </header>

      <div id="input-example-0" class="example">
        <p class="example-label">
          <strong>Example:</strong>
          <a class="example-clipboard" data-tooltip="Click to copy code" data-clipboard-target="#input-example-0-code">Copy</a>
        </p>
        <article class="example-preview">
            <div class="example-output"><input type="text" name="first_name" placeholder="e.g. Alex"></div>
          <div id="input-example-0-code" class="example-code">{% highlight html %}<input type="text" name="first_name" placeholder="e.g. Alex">{% endhighlight %}</div>
        </article>
      </div>

    <article id="input-type" class="attribute attribute--required">
      <header class="attribute-header">
        <h3 class="attribute-name">
          <code class="tag" data-tooltip="Click to copy" data-clipboard-text="type">
            type
          </code>
        </h3>
        <div class="attribute-description">
          <p>Defines the type of form input.</p>

            <strong class="attribute-is-required">Required.</strong>
        </div>
      </header>

      <div class="attribute-values">
          <article id="input-type-text" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy type=&quot;text&quot;" data-clipboard-text="type=&quot;text&quot;">
                      "text"
                  </code>
                </h4>
              <div class="value-description">
                <p>Simple single line text input that accepts any type of character</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  type="text"></input></div>
            </aside>
          </article>
          <article id="input-type-email" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy type=&quot;email&quot;" data-clipboard-text="type=&quot;email&quot;">
                      "email"
                  </code>
                </h4>
              <div class="value-description">
                <p>Like a text input, but the browser will try to only allow valid email addresses.</p>
<p>On mobile devices, the email keyboard will show up.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  type="email"></input></div>
            </aside>
          </article>
          <article id="input-type-number" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy type=&quot;number&quot;" data-clipboard-text="type=&quot;number&quot;">
                      "number"
                  </code>
                </h4>
              <div class="value-description">
                <p>Like a text input, but the browser will try to only allow valid numbers.</p>
<p>On mobile devices, the number keyboard will show up.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  type="number"></input></div>
            </aside>
          </article>
          <article id="input-type-checkbox" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy type=&quot;checkbox&quot;" data-clipboard-text="type=&quot;checkbox&quot;">
                      "checkbox"
                  </code>
                </h4>
              <div class="value-description">
                <p>A toggle checkbox that can only be one of two states: checked or unchecked. The value is only submitted by the form if the checkbox is checked.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  type="checkbox"></input></div>
            </aside>
          </article>
          <article id="input-type-undefined" class="value">
            <header class="value-header">
              <div class="value-description">
                <p>You can wrap a checkbox in a label, to increase the click area.</p>

{% highlight html %}
<label>
  <input type="checkbox">
  I accept the terms and conditions
</label>
{% endhighlight %}
<p>Notice how clicking the text toggles the checkbox.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><label>
  <input type="checkbox">
  I accept the terms and conditions
</label></div>
            </aside>
          </article>
          <article id="input-type-radio" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy type=&quot;radio&quot;" data-clipboard-text="type=&quot;radio&quot;">
                      "radio"
                  </code>
                </h4>
              <div class="value-description">
                <p>Needs to be used used in combination with other radio buttons, so that they are mutually exclusive.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  type="radio"></input></div>
            </aside>
          </article>
          <article id="input-type-undefined" class="value">
            <header class="value-header">
              <div class="value-description">
                <p>You link radio buttons through a similar <code>name</code> value:</p>

{% highlight html %}
<label>
  <input type="radio" name="newsletter" value="yes">
  Yes
</label>
<label>
  <input type="radio" name="newsletter" value="no">
  No
</label>
{% endhighlight %}
<p>Notice how clicking one deselects the other.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><label>
  <input type="radio" name="newsletter" value="yes">
  Yes
</label>
<label>
  <input type="radio" name="newsletter" value="no">
  No
</label></div>
            </aside>
          </article>
          <article id="input-type-submit" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy type=&quot;submit&quot;" data-clipboard-text="type=&quot;submit&quot;">
                      "submit"
                  </code>
                </h4>
              <div class="value-description">
                <p>Submit button that is triggered when clicked or when pressing Enter.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  type="submit"></input></div>
            </aside>
          </article>
      </div>
    </article>
    <article id="input-name" class="attribute attribute--required">
      <header class="attribute-header">
        <h3 class="attribute-name">
          <code class="tag" data-tooltip="Click to copy" data-clipboard-text="name">
            name
          </code>
        </h3>
        <div class="attribute-description">
          <p>Defines the unique identifier for that input within the form. It allows the server to access each input&#39;s value when submitted.</p>

            <strong class="attribute-is-required">Required.</strong>
        </div>
      </header>

      <div class="attribute-values">
          <article id="input-name-first_name" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy name=&quot;first_name&quot;" data-clipboard-text="name=&quot;first_name&quot;">
                      "first_name"
                  </code>
                </h4>
              <div class="value-description">
                <p>The name value must be unique within the context of a <code>&lt;form&gt;</code> container.</p>
<p>It can only contain alphanumeric characters <code>a-z</code> <code>A-Z</code> <code>0-9</code> and some special characters like <code>-</code> <code>_</code>… but no space.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  name="first_name"></input></div>
            </aside>
          </article>
      </div>
    </article>
    <article id="input-placeholder" class="attribute">
      <header class="attribute-header">
        <h3 class="attribute-name">
          <code class="tag" data-tooltip="Click to copy" data-clipboard-text="placeholder">
            placeholder
          </code>
        </h3>
        <div class="attribute-description">
          <p>Defines a non-selectable placeholder text that only appears when the input is empty.</p>

        </div>
      </header>

      <div class="attribute-values">
          <article id="input-placeholder-eg-alexsmithcom" class="value">
            <header class="value-header">
                <h4 class="value-name">
                  <code class="tag" data-tooltip="Click to copy placeholder=&quot;e.g. alex@smith.com&quot;" data-clipboard-text="placeholder=&quot;e.g. alex@smith.com&quot;">
                      "e.g. alex@smith.com"
                  </code>
                </h4>
              <div class="value-description">
                <p>You can hint at the format expected for the input.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  placeholder="e.g. alex@smith.com"></input></div>
            </aside>
          </article>
          <article id="input-placeholder-undefined" class="value">
            <header class="value-header">
              <div class="value-description">
                <p>As a best practice, it is recommended to have a label to describe the input, and use the placeholder to showcase an example:</p>

{% highlight html %}
<form>
  <label>Email</label><br>
  <input type="email" name="email" placeholder="e.g. alex@smith.com">
</form>
{% endhighlight %}
<p>Notice how the placeholder disappears on focus, hence the need to maintain a separate label.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><form>
  <label>Email</label><br>
  <input type="email" name="email" placeholder="e.g. alex@smith.com">
</form></div>
            </aside>
          </article>
      </div>
    </article>
    <article id="input-required" class="attribute attribute--novaluebut">
      <header class="attribute-header">
        <h3 class="attribute-name">
          <code class="tag" data-tooltip="Click to copy" data-clipboard-text="required">
            required
          </code>
        </h3>
        <div class="attribute-description">
          <p>Tells the browser that this input is <strong>required</strong>. Leaving it empty will show a warning.</p>

            <strong class="attribute-is-novalue">No value required.</strong>
        </div>
      </header>

      <div class="attribute-values">
          <article id="input-required-undefined" class="value">
            <header class="value-header">
              <div class="value-description">
                <p>You simply need to add the <code>required</code> attribute with no value:</p>

{% highlight html %}
<form>
  <input type="text" required>
</form>
{% endhighlight %}
<p>The browser should show a warning if you try to submit the form with an empty text input.</p>

              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><form>
  <input type="text" required>
</form></div>
            </aside>
          </article>
      </div>
    </article>
    <article id="input-disabled" class="attribute attribute--novalue">
      <header class="attribute-header">
        <h3 class="attribute-name">
          <code class="tag" data-tooltip="Click to copy" data-clipboard-text="disabled">
            disabled
          </code>
        </h3>
        <div class="attribute-description">
          <p>Disables the input.</p>

            <strong class="attribute-is-novalue">No value required.</strong>
        </div>
      </header>

      <div class="attribute-values">
          <article id="input-disabled-undefined" class="value">
            <header class="value-header">
              <div class="value-description">
                
              </div>
            </header>
            <aside class="value-preview">
              <div class="value-output"><input  disabled></input></div>
            </aside>
          </article>
      </div>
    </article>
</section>
